Widget error integrate it with CloudKit

A few months back, I launched an app that operated solely on a local level. Recently, I've begun the process of integrating it with CloudKit, and so far, the model integration has been successful. I've utilized SwiftData for this task, making it relatively straightforward to adjust the models, as shown below: `

@Relationship(deleteRule: .cascade, inverse: \ItemForCategory.category)

var itemForCategory : [ItemForCategory]? = [ItemForCategory]()

`

In my initial version of the code, the widget functioned perfectly. However, I've encountered an error recently stating Missing return in instance method expected to return 'ItemForCategory?'.

 @MainActor
    private func getLastItem () -> ItemForCategory? {
      guard let modelContainer = try? ModelContainer(for: Category.self) else {
        return nil
      }
      let descriptor = FetchDescriptor<Category>()
        
      let appCategories = try? modelContainer.mainContext.fetch(descriptor)
      
      let lastItem = appCategories?.compactMap { $0.itemForCategory }.last
        
    return lastItem
    }

The error surfaces at the return line of code. I'm hopeful that someone can assist me in resolving this issue. Thank you very much.